package de.tudarmstadt.ukp.muip.fibqdojo.visitor;

import com.google.common.base.Optional;

import de.tudarmstadt.ukp.muip.fibqdojo.Sentence;
import de.tudarmstadt.ukp.muip.fibqdojo.SentenceToken;
import de.tudarmstadt.ukp.muip.fibqdojo.Token;
import de.tudarmstadt.ukp.muip.fibqdojo.interfaces.IFIBQSentenceToken;
import de.tudarmstadt.ukp.muip.fibqdojo.interfaces.IStructureVisitor;
import de.tudarmstadt.ukp.muip.fibqdojo.japanese.JapaneseToken;

/**
 * Returns the marked token of the sentence. The marked token is the one that is
 * supposed to be replaced by a blank, hence returning the marked token is equal
 * to return the correct answer.
 * 
 * @author Tobias Horsmann
 */
public class SentenceAnswerVisitor implements IStructureVisitor {

    private Optional<String> answer = Optional.absent();

    public Optional<String> getAnswer() {
        return answer;
    }

    @Override
    public void visit(JapaneseToken token) {
    }

    @Override
    public void visit(Token token) {
    }

    @Override
    public void visit(SentenceToken token) {
        if (token.isMarkedBlank()) {
            GetFormVisitor visitor = new GetFormVisitor();
            token.accept(visitor);
            answer = Optional.of(visitor.getForm().toLowerCase());
        }
    }

    @Override
    public void visit(Sentence sentence) {
        for (IFIBQSentenceToken token : sentence.getSentenceTokens()) {
            token.accept(this);
        }
    }

}
